#include <iostream>
#include <vector>
using namespace std;
int minOperations(vector<int> &nums, int x)
{
    int sum = 0;
    for (int i = 0; i < nums.size(); i++)
    {
        sum += nums[i];
    }
    int target = sum - x;
    if (target < 0)
        return -1;
    int len = -1;
    int ret = 0;
    for (int left = 0, right = 0; right < nums.size(); right++)
    {
        ret += nums[right];
        while (ret > target)
        {
            ret -= nums[left++];
        }
        if (ret == target)
        {
            len = max(len, right - left + 1);
        }
    }
    return len == -1 ? len : nums.size() - len;
}